using System;
using System.Collections.Generic;

namespace VisionarySystems.TimeRegi.View.WorkTimeCalculator
{
    public class BreakTimeCalculator
    {
        private readonly TimeSpan m_BrakeTime;

	    public BreakTimeCalculator(TimeSpan BrakeTime)
        {
            m_BrakeTime = BrakeTime;
        }

	    public TimeSpan BreakPerDay
	    {
			get { return m_BrakeTime; }
	    }

	    public TimeSpan GetBrakeTime(DateTime StartDate, DateTime EndDate)
        {
            TimeSpan result = new TimeSpan();
            DateTime currentDate = StartDate.Date;
            for (int dayNo = 1; currentDate <= EndDate; dayNo++)
            {
                result = result.Add(ExpectedBreakTimePerDay(currentDate.DayOfWeek));
                currentDate = StartDate.Date.AddDays(dayNo);
            }
            return result;
        }

        public TimeSpan ExpectedBreakTimePerDay(DayOfWeek TheDay)
        {
            TimeSpan result ;
            if ((TheDay == DayOfWeek.Saturday) || (TheDay == DayOfWeek.Sunday)) // Satterday and sunday includes no breaks 
                result = new TimeSpan();
            else 
                result = m_BrakeTime;
            return result;
        }

        public TimeSpan GetBrakeTime(IEnumerable<DateTime> WorkingDates)
        {
            var result = new TimeSpan();
            foreach (var workDate in WorkingDates)
                result = result.Add(ExpectedBreakTimePerDay(workDate.DayOfWeek));
            return result;
        }
    }
}